﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VincentUtil.Ntp
{
    public abstract class NtpMessage
    {
        protected const int _referenceTimeIndex = 16;
        protected const int _originTimeIndex = 24;
        protected const int _receiveTimeIndex = 32;
        protected const int _transmitTimeIndex = 40;

        /// <summary>
        /// 发送：发送请求的时间
        /// 接收：复制该时间
        /// </summary>
        public DateTime OriginTime;

        /// <summary>
        /// 发送：发送请求的时间
        /// 接收：发送响应的时间
        /// </summary>
        public DateTime TransmitTime;

        public virtual byte[] BuildNTPBytes()
        {
            byte[] ntpData = new byte[48];
            NtpUtil.TryWriteNtpTime(ntpData, _originTimeIndex, OriginTime);
            NtpUtil.TryWriteNtpTime(ntpData, _transmitTimeIndex, TransmitTime);
            return ntpData;
        }

        protected NtpMessage(DateTime originTime, DateTime transmitTime)
        {
            OriginTime = originTime;
            TransmitTime = transmitTime;
        }
    }

}
